package com.goods.business.service.imp;

import com.goods.business.mapper.ConsumerMapper;
import com.goods.business.service.ConsumerService;
import com.goods.common.vo.business.ConsumerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
@ComponentScan(value = "com.goods.business.mappper")
public class ConsumerServiceImpl implements ConsumerService {
    @Autowired
    ConsumerMapper consumerMapper;
//CollectionUtils.isEmpty()
    @Override
    public List<ConsumerVO> findConsumerList(Integer pageNum, Integer pageSize, String name, String address, String contact) {
        List<ConsumerVO> consumerVOS = consumerMapper.selectAll();
        List<ConsumerVO> runconsumerVOS = new ArrayList<>();
        if (!StringUtils.isEmpty(name)){
            for (ConsumerVO consumerVO : consumerVOS) {
                if (consumerVO.getName().contains(name)){
                    runconsumerVOS.add(consumerVO);
                }
            }
            return runconsumerVOS;
        }
        if (!StringUtils.isEmpty(address)){
            for (ConsumerVO consumerVO : consumerVOS) {
                if (consumerVO.getAddress().contains(address)){
                    runconsumerVOS.add(consumerVO);
                }
            }
            return runconsumerVOS;
        }
        if (!StringUtils.isEmpty(contact)){
            for (ConsumerVO consumerVO : consumerVOS) {
                if (consumerVO.getContact().contains(contact)){
                    runconsumerVOS.add(consumerVO);
                }
            }
            return runconsumerVOS;
        }


        return consumerVOS;
    }
}
